<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        // js中有哪些内置对象? Math Array Date String Rex Num
        // Array
        function Person() {};
        function Person() {};
        var yq = new Person();
        var yq = new Person();
        var yq = new Person();
        Person.prototype.sayHi = function () {
            console.log('hello');
        }
        Person.prototype.sayHi = function () {
            console.log('hello');
        }
        Person.prototype.sayHi = function () {
            console.log('hello')
        }
        yq.sayHi();
        yq.sayHi();
        yq.sayHi();
        Array.prototype.sayHi = function () {
            console.log('你好');
        }
        Array.prototype.sayHi = function () {
            console.log('你好');
        }
        Array.prototype.sayHi = function () {
            console.log('你好');
        }
        // 系统规定好的方法，如果要往内置对象的原型上添加方法，相当于更改对象
        // webstorm中可以查看内置对象中的方法实现
        Array.prototype.concat = function () {}
        Array.prototype.concat = function () {}
        Array.prototype.concat = function () {}
        console.dir(Array);
        // 需求: 请问Array中有没有bubble方法，冒泡排序方法
        // 能不能给Array构造函数添加冒泡排序方法
        Array.prototype.bubble = function () {
            for(var i = 0; i < this.length - 1; i++) {
                for(var j = 0; j < this.length - 1 - i;j++) {
                    if(this[j] > this[j + 1]) {
                        var temp = this[j];
                        this[j] = this[j + 1];
                        this[j + 1] = temp;
                    }
                }
            }
        }
        Array.prototype.bubble = function () {
            for(var i = 0; i < this.length -1; i++) {
                for(var j = 0; j < this.length - 1 - i;j++) {
                    if(this[j] > this[j + 1]) {
                        var temp = this[j];
                        this[j] = this[j + 1];
                        this[j + 1] = this[j + 1];
                    }
                }
            }
        }
        Array.prototype.bubble = function () {
            for(var i = 0; i < this.length - 1; i ++) {
                for(var j = 0; j < this.length - 1 - i; j ++) {
                    if(this[j] > this[j + 1]) {
                        var temp = this[j];
                        this[j] = this[j + 1];
                        this[j + 1] = this[j + 1];
                    }
                }
            }
        }
        Array.prototype.bubble = function () {
            for(var i = 0; i < this.length - 1 -i; i++) {
                for(var j = 0; j < this.length - 1 -i; j++) {
                    if(this[j] > this[j + 1]) {
                        var temp = this[j];
                        this[j] = this[j + 1];
                        this[j + 1] = this[j];
                    }
                }
            }
        }
        var arr = [2,1,3,6,4,0,9];
        arr.bubble();
        arr.bubble();
        arr.bubble();
                console.log(arr);
        var arr = [1,2,4,4];
        arr.reverse();
        var str = new String();
        String.prototype.sayHi = function () {
            alert(1);
        }
        console.log(str)
        // 可以为内置对象添加原型方法
    </script>
</body>
</html>